/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package RTPEditor;

import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

/**
 *
 * @author Zarko Coklin
 */
public class IntegerValidator extends InputVerifier
{
    public IntegerValidator()
    {
    }

    public boolean verify(JComponent input)
    {
        int         value;
        JTextField  txtField = (JTextField)input;

        if (txtField.isEnabled() == true)
        {
            try
            {
                value = Integer.parseInt(txtField.getText());
            }
            catch (NumberFormatException exc)
            {
                JOptionPane.showMessageDialog(input,
                        "Value must be a numeric value",
                        "Value validation",
                        JOptionPane.ERROR_MESSAGE);
                return false;

            }
            if (value <= 0)
            {
                JOptionPane.showMessageDialog(input,
                        "Value must be a positive",
                        "Value validation",
                        JOptionPane.ERROR_MESSAGE);
                return false;
            }
        }
        return true;
    }

}
